package com.jkl.controller.index;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.index.PJIndex;
import com.jkl.service.index.inter.IPJIndexServiceInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/jky")
@Slf4j
public class IndexController {

	@Autowired
	private HttpServletRequest request;

	@Autowired
	private HttpServletResponse response;

	@Autowired
	private IPJIndexServiceInterface indexService;

	@PostMapping("/queryIndexByYearAndDeptParentId")
	public BaseResponseDTO queryIndexByYearAndDeptParentId(@RequestBody PJIndex pjIndex) {
		List<PJIndex> pjIndexList = indexService.queryIndexByYearAndDeptParentId(pjIndex);
		BaseResponseDTO returnDto = new BaseResponseDTO();
		JSONObject jo = new JSONObject();
		jo.put("indexList", (JSONArray) JSONArray.toJSON(pjIndexList));
		returnDto.setReturnData(jo);
		return returnDto;
	}

	@PostMapping("/saveIndexList")
	public BaseResponseDTO saveIndexList(@RequestBody List<PJIndex> pjIndex) {
		BaseResponseDTO returnDto = new BaseResponseDTO();
		try {
			indexService.saveIndexList(pjIndex);
		} catch (Exception e) {
			returnDto.setResultCode("0001").setResultMessage("指标数据保存失败");
		}
		return returnDto;
	}

}
